import torch
from perceptron_model import Perceptron  # 导入单层感知机模型类
from net_model import MultiLayerPerceptron  # 导入多层感知机模型类

# 创建模型实例
perceptron_model = Perceptron()
net_model = MultiLayerPerceptron()

# 加载已保存的单层感知机模型参数
perceptron_model.load_state_dict(torch.load('perceptron_model.pth', map_location=torch.device('cpu')))
# 设置模型为评估模式
perceptron_model.eval()
# 输入数据进行推理
print('perceptron model structure')
print(perceptron_model)
with torch.no_grad():
    x_test = torch.tensor([10.0])
    y_test = perceptron_model.forward(x_test.unsqueeze(0))
    print(f'test input: {x_test.item()},test output: {y_test.item()}')
    
#加载已保存的多层感知机模型参数
net_model.load_state_dict(torch.load('net_model.pth', map_location=torch.device('cpu')))
# 设置模型为评估模式
net_model.eval()
# 输入数据进行推理
print('net model structure')
print(net_model)
with torch.no_grad():
    x_test = torch.tensor([10.0])
    y_test = net_model.forward(x_test.unsqueeze(0))
    print(f'test input: {x_test.item()},test output: {y_test.item()}')  


